package com.yunxi.controller.sys;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sys.pojo.CountryVO;
import com.yunxi.sys.service.CountryDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-21
 */
@RestController
@RequestMapping("/admin/country")
@Api(tags = "sys:country", description = "国家接口")
public class CountryController {
   private static final Logger logger = LoggerFactory.getLogger(CountryController.class);

   @Autowired
   CountryDubboService countryDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(CountryVO countryVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(countryDubboService.findPageByVO(countryVO, pageNum, pageSize));
   }

   @GetMapping("/list")
   @ApiOperation(value = "查询")
   public ApiResult list(CountryVO countryVO) throws Exception {
      return ResponseUtil.ok(countryDubboService.listByVO(countryVO));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(countryDubboService.getById(id));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody CountryVO countryVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      countryDubboService.saveOrUpdate(countryVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<CountryVO> countryVOList) throws Exception {
      countryDubboService.removeByList(countryVOList);
      return ResponseUtil.ok("success");
   }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(countryDubboService.findMapByList(params));
}*/
}
